from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import redis
from flask_wtf.csrf import CSRFProtect
from flask_session import Session
from congig import config
from info.utils.common import do_index_class

redis_store = None

db=SQLAlchemy()

def tool_app(config_name = 'developementConfig'):
    app = Flask(__name__,static_url_path='/static',static_folder='static')
    app.config.from_object(config[config_name])
    db.init_app(app)
    global redis_store
    redis_store=redis.StrictRedis(host=config[config_name].REDIS_HOST,port=config[config_name].REDIS_PORT)
    # CSRFProtect(app)
    Session(app)
    from info.modules.index import index_blu
    app.register_blueprint(index_blu)
    from info.modules.passport import passport_blu
    app.register_blueprint(passport_blu)
    app.add_template_filter(do_index_class,'index_class')

    return app

